import GAMEFUNC_ from "./func.js";
import Block from "./Block.js";
import CAMERA_CLASS from "./cameraClass.js";
import  MAIN_CANVAS from "./CANVAS.js";

export default class RoleClass {

    static MAIN_RENDERER(runtime)
    {


    }

    static TICK(runtime)
    {
        if(!GAMEFUNC_.RUNTIME.IN_GAME_LAYOUT(runtime))
        {
            return
        }

        RoleClass.MAIN_EVENTHANDLER_(runtime)

    }

    static RUNTIME_LAYOUT_START(runtime)
    {
        if(!GAMEFUNC_.RUNTIME.IN_GAME_LAYOUT(runtime)){
                return}


        RoleClass.INIT_EVENTHANDLER(runtime)
        RoleClass.CANVAS.INIT_EVENTHANDLER(runtime)


    }

    static MAIN_EVENTHANDLER_(runtime){

            RoleClass.ROLE_RUNTIME_FUNC.eventhandler(runtime)
            RoleClass.CANVAS.EVENTHANDLER(runtime)




    }

     static INIT_EVENTHANDLER(runtime)
    {

        this.DATA.INIT_DATA(runtime)

    }


    // 数据存储

    static DATA={

        INIT_DATA(runtime)
        {

            RoleClass.RoleSprite=runtime.objects.Role.getFirstInstance();
            RoleClass.RoleBehavior={
                moveto:RoleClass.RoleSprite.behaviors.moveto
            }




            RoleClass.PROPERTIES={
                ACTION_POINT:9999
            }

            RoleClass.SELF_BLOCK_UID=0

        }


    }


     static CANVAS ={



        async TEXT_(runtime)
        {


        },


        async INIT_EVENTHANDLER(runtime)
        {


            MAIN_CANVAS.TEXT_RUNTIME.INIT_TEXT(runtime)

            const renderingConfig =[50,50,"canvas_HUD"]

            this.ACTION_POINT_TEXT =MAIN_CANVAS.TEXT_RUNTIME.NEW(runtime,renderingConfig)











        },

        EVENTHANDLER(runtime)
        {

            if (this.ACTION_POINT_TEXT==null){return}

            this.ACTION_POINT_TEXT.text="ACTION_POINT: "+RoleClass.PROPERTIES.ACTION_POINT
            this.ACTION_POINT_TEXT.fontColor=[5,5,5]





        }

    }



     static ROLE_ACTION={

        async ROLE_MOVE(runtime,block)
        {

            if(!RoleClass.ROLE_RUNTIME_FUNC.GET_ACTION_STATE(runtime)) {return}

            if (block.instVars.DIS>Block.MAX_REACH_DISTANCE) {return}

            if(block.uid!=RoleClass.SELF_BLOCK_UID)
            {
                RoleClass.ROLE_NORMAL_FUN.MOVE_TO_BLOCK(runtime,block)
                // - ACTION_POINT
                RoleClass.PROPERTIES.ACTION_POINT-=1

            }


        },



    }


    static ROLE_NORMAL_FUN={

        //MOVE TO THIS BLOCK

        MOVE_TO_BLOCK(runtime, block)
        {
           RoleClass.RoleBehavior.moveto.moveToPosition(block.x,block.y,true)

        }

    }


    static ROLE_RUNTIME_FUNC={




        eventhandler(runtime)
        {
            RoleClass.ROLE_RUNTIME_FUNC.GET_SELF_BLOCK(runtime)
            RoleClass.ROLE_RUNTIME_FUNC.CAMEER_RENDERBUFFER(runtime)
            RoleClass.RoleSprite.moveToTop()
        },


        GET_SELF_BLOCK(runtime)
        {
            for(let BLOCK_ of runtime.objects.f_block.instances())
            {
                if(RoleClass.RoleSprite.testOverlap(BLOCK_))
                {
                    RoleClass.SELF_BLOCK_UID=BLOCK_.uid
                    return RoleClass.SELF_BLOCK_UID

                }

            }
        },


        // RETURN IF CAN DO ACTION
        GET_ACTION_STATE(runtime)
        {
            if (RoleClass.PROPERTIES.ACTION_POINT<0)
            {
                return  false
            }

            else  {

                return true
            }


        },


        CAMEER_RENDERBUFFER(runtime){

            CAMERA_CLASS.MOVEMENT_.MOVETOPOS(runtime,RoleClass.RoleSprite.x,RoleClass.RoleSprite.y)
        }

    }


    static RUNTIME_INPUT={

        _INPUT_MOUSE_DOWN(e,runtime)
        {

            if(e.button==0)
            {

            }


        },

        _INPUT_KEY_DOWN(e,runtime)
        {},

        _INPUT_WHEEL_MOVE(e,runtime)
        {},



    }



}